/**
 * @Author : woon
 * @Timestamp : 2016-12-23
 */
var nf = sm("do_Notification");
var page = sm("do_Page");
var dialog = sm("do_Dialog");
var openHelper = require("helper/open");
var http = require("helper/http");
var circleUrl = require("url/circle");
var userUtil = require("helper/user");
var imHelper = require("helper/im");
var friendHelper = require("helper/friend");

ui("$").setMapping({
	"alayoutRoot.tag" : "bussId",
	"btnDelete.tag" : "type",
	"labelIM.tag": "imId"
});

/**
 * type：消息类型【Chat:单聊;GroupChat:群聊;comment:评论;zan:点赞;friend:好友申请;circleInvite:圈子邀请我加入;circleApply:申请加入我的圈子;adminPush:后台推送】
 * imId：聊天用户imId【单聊、群聊id】
 * bussId：业务id【好友申请业务id、圈子邀请业务id、申请加入我的圈子业务id、后台推送的消息id】
 */
ui("btnDelete").on("touch", function(data, e) {
	if(userUtil.loginToken()==""){
		nf.toast("您还未登陆");
		return;
	}
	var type = ui("btnDelete").tag;
	var imId = ui("labelIM").tag;
	var bussId = ui("alayoutRoot").tag;
	
	if(type=="comment"){//评论
		imHelper.clearUnReadCount2Her({herId:"comment"});
		page.fire("message_delete_comment_row");
		
	}else if(type=="zan"){//点赞
		imHelper.clearUnReadCount2Her({herId:"zan"});
		page.fire("message_delete_zan_row");
		
	}else if(type=="Chat"){
		page.fire("message_delete_Chat_row",imId);
		
	}else if(type=="GroupChat"){
		page.fire("message_delete_GroupChat_row",imId);
		
	}else if(type=="friend" && bussId != ""){
		friendHelper.removeFriendApply(bussId,function(data){
			page.fire("message_reflash_friend", bussId);
		});
	}else if(type=="circleInvite" && bussId != ""){
		http.post(circleUrl.url.invite.ignore, {id:bussId}, function(data) {
			page.fire("message_reflash_circle_invite", bussId);
		});
	}else if(type=="circleApply" && bussId != ""){
		http.post(circleUrl.url.apply.remove, {id:bussId}, function(data) {
			page.fire("message_reflash_circle_apply", bussId);
		});
	}else if(type=="adminPush"){//后台推送
		imHelper.removeAdminPushCahce(bussId);//删除这条推送消息
		page.fire("message_delete_adminPush_row",bussId);
		
	}else{
		nf.toast("不支持该业务类型");
	}
})
